﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web_cuiki
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        public string Catalog;
        public string HienThiSach;
        public string SachMoi;
        public string cartView;
        protected void Page_Load(object sender, EventArgs e)
        {
            cartView = "";
            if (Session["dsChiTiet"] != null)
            {
                string strds = (string)Session["dsChiTiet"];
                List<ChiTietDonDatHangDTO> dsChiTiet = stringToListChiTiet(strds);               
                cartView += " <div class='home_cart_content'>"
              + dsChiTiet.Count + " items"
              + "</div> <a href='Cart.aspx' class='view_cart'>view cart</a>";
            }
            if (IsPostBack == false)
            {
                Catalog = "";
                SachMoi = "";
                

                
                List<THE_LOAI> DSTL = TheLoaiDAO.LayDSTheLoai();
                for (int i = 0; i < DSTL.Count; i++)
                {
                    Catalog += "<li> <a href='Default.aspx?TheLoai=" + DSTL[i].MaTheLoai + "'>";
                    Catalog += DSTL[i].TenTheLoai + "</a></li> ";
                }
                List<SAN_PHAM> DSSM = SanPhamDAO.LayDSSanPhamMoi();
                for (int i = 0; i < DSSM.Count; i++)
                {
                    SachMoi += "<div class='new_prod_box'>";
                    SachMoi += "    <a href='#'>"+DSSM[i].TenSanPham+"</a>";
                    SachMoi += "    <div class='new_prod_bg'>";
                    SachMoi += "    <span class='new_icon'><img src='images/new_icon.gif' alt='' title=''   /></span>";
                    SachMoi += "    <a href='Detail.aspx?masach=" + DSSM[i].MaSanPham + "'><img src='" + DSSM[i].HinhAnh + "' alt='' title='' class='thumb' border='0' width=60px' height='95px'/></a>";
                    SachMoi += "    </div>";
                    SachMoi += "</div>";
                    if (i + 1 % 3 == 0)
                    {
                        SachMoi +="<br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> ";
                    }
                }
            }
            if(Request.QueryString["TheLoai"]!=null)
            {
                String MaTheLoai = Request.QueryString["TheLoai"];
                List<SAN_PHAM> DSSP = SanPhamDAO.LayDSTheoMaTheLoai(MaTheLoai);
                HienThiSach= "";
                for (int i = 0; i < DSSP.Count; i++)
                {
                        HienThiSach+= "    <div class='feat_prod_box'>";
                        HienThiSach += " <div class='prod_img'><a href='Detail.aspx?masach=" + DSSP[i].MaSanPham + "'><img src='" + DSSP[i].HinhAnh + "' alt='' title='' border='0'  width=98px' height='150px'/></a></div>";           
                        HienThiSach+= " <div class='prod_det_box'>";
                	    HienThiSach+= "     <div class='box_top'></div>";
                        HienThiSach+= "     <div class='box_center'>";
                        HienThiSach+= "     <div class='prod_title'>"+DSSP[i].TenSanPham+"</div>";
                        HienThiSach+= "     <p class='details'>"+DSSP[i].MoTa+"</p>";
                        HienThiSach += "     <a href='Detail.aspx?masach=" + DSSP[i] .MaSanPham+ "' class='more'>- more details -</a>";
                        HienThiSach+= "     <div class='clear'></div>";
                        HienThiSach+= "     </div>";
                        HienThiSach+= "     <div class='box_bottom'></div>";
                        HienThiSach+= " </div>";   
                        HienThiSach+= " <div class='clear'></div>";
                        HienThiSach += " </div>";
                }
            }
        }


        private List<ChiTietDonDatHangDTO> stringToListChiTiet(string str)
        {
            List<ChiTietDonDatHangDTO> rs = new List<ChiTietDonDatHangDTO>();
            str = WSRequest.EditToBasicFormat(str);
            WSRequest.XMLToObject<List<ChiTietDonDatHangDTO>>(ref rs, str);
            return rs;
        }


        //public int TheLoai { get; set; }
    }
}